FROM golang:1.15.11-alpine3.12 AS builder
RUN apk --no-cache add build-base
WORKDIR /build
RUN adduser -u 10001 -D app-runner

ENV GOPROXY https://goproxy.cn
COPY go.mod .
COPY go.sum .
RUN go mod download

COPY . .
RUN go build -tags musl

FROM alpine:3.12 AS runner
WORKDIR /app
COPY --from=builder /build/test-netserver /app/
COPY --from=builder /build/conf/ca-cert.pem /app/conf/
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
USER app-runner
ENTRYPOINT ["./test-netserver"]